// 创建枚举对象，用于界面显示转换
function createEnumObject(enums) {
  let labels = null
  let values = null
  let labelAndValues = []

  return {
    getLabels() {
      if (!labels) {
        labels = enums.map((item) => item.label)
      }
      return labels
    },
    getValues() {
      if (!values) {
        values = enums.map((item) => item.value)
      }
      return values
    },

    getLabelAndValues() {
      labelAndValues = []
      enums.forEach(item => {
        labelAndValues.push({
          label: item.label,
          value: item.value
        })
      })
      return labelAndValues
    },

    getLabel(value) {
      let index = this.getValues().indexOf(value)

      if (index > -1) {
        return this.getLabels()[index]
      }
    },

    getValue(label) {
      let index = this.getLabels().indexOf(label)

      if (index > -1) {
        return this.getValues()[index]
      }
    },

    getItem(valueOrLabel) {
      let index = this.getValues().indexOf(valueOrLabel)

      if (index < 0) {
        index = this.getLabels().indexOf(valueOrLabel)
      }

      if (index > -1) {
        return enums[index]
      }
    },
  }
}


/** 回复状态 */
// 枚举值，用于逻辑判断
export const replyStatusEnum = {
  //待回复
  PENDING: "1",
  // 已回复
  REPLIED: "2",
  // 拒绝回复
  REJECTED: "3",
}

// 枚举值配置，用于属性扩展
const replyStatusEnumConfig = [{
  value: replyStatusEnum.PENDING,
  label: '待回复',
  color: 'yellow',
},
  {
    value: replyStatusEnum.REPLIED,
    label: '已回复',
    color: 'green',
  },
  {
    value: replyStatusEnum.REJECTED,
    label: '拒绝回复',
    color: 'gray',
  },
]

// 枚举值对象，用于数值转换
export const replyStatusEnumObj = createEnumObject(replyStatusEnumConfig)



/** 已读状态 */
// 枚举值，用于逻辑判断
export const readStatusEnum = {
  //未读
  UNREAD: 0,
  // 已读
  READ: 1,
}

// 枚举值配置，用于属性扩展
const readStatusEnumConfig = [{
  value: replyStatusEnum.PENDING,
  label: '待回复',
  color: 'yellow',
},
  {
    value: readStatusEnum.UNREAD,
    label: '未读',
    color: 'green',
  },
  {
    value: readStatusEnum.READ,
    label: '已读',
    color: 'gray',
  },
]

// 枚举值对象，用于数值转换
export const readStatusEnumObj = createEnumObject(readStatusEnumConfig)

